package naito_rescue.util.sort;

import java.util.*;
import sample.*;
import rescuecore2.messages.*;
import rescuecore2.worldmodel.*;
import rescuecore2.Constants;
import rescuecore2.standard.components.*;
import rescuecore2.standard.entities.*;
import rescuecore2.standard.messages.*;
import rescuecore2.misc.geometry.*;

import naito_rescue.agent.*;
import naito_rescue.util.fb.*;

public class ComparatorUtils
{
	public static Comparator<StandardEntity> ID_Ascending_Comparator = 
		new Comparator<StandardEntity>(){
			@Override
			public int compare(StandardEntity e1, StandardEntity e2){
				return e1.getID().getValue() - e2.getID().getValue();
			}
		};
	public static Comparator<StandardEntity> ID_Descending_Comparator = 
		new Comparator<StandardEntity>(){
			@Override
			public int compare(StandardEntity e1, StandardEntity e2){
				return e2.getID().getValue() - e1.getID().getValue();
			}
		};
	public static Comparator<Building> Building_Priority_Comparator = null;
	public static Comparator<Building> getBuildingPriorityComparator(NAITOAgent owner){
		//lazy initialize
		if(Building_Priority_Comparator == null){
			Building_Priority_Comparator = new BuildingPriorityComparator(owner);
		}
		return Building_Priority_Comparator;
	}
	
	private static class BuildingPriorityComparator implements Comparator<Building>
	{
		NAITOAgent owner;
		public BuildingPriorityComparator(NAITOAgent owner){ this.owner = owner; }
		
		@Override
		public int compare(Building b1, Building b2){
			int priority1 = FireBrigadeUtils.updateBuildingPriority(owner, b1);
			int priority2 = FireBrigadeUtils.updateBuildingPriority(owner, b2);
			return priority2 - priority1;
		}		 
	}
}
